<template>
  <div class="TryNewProducts">
    <div class="ProductsTitle">
      <div class="category">
        <div :class="['group',index==0?'selected':'']" @click="getList(0)">团餐</div>
        <div :class="['normal',index==1?'selected':'']" @click="getList(1)">普通商品</div>
      </div>
    </div>
    <!--  -->
    <van-list v-model="loading" :finished="finished" @load="onLoad">
      <div class="goodsList">
        <!--  "-->
        <div class="item" v-for="(item,index) in list" :key="index">
          <div class="goods">
            <!-- :src="`${resourceURL}${item.imageurl}`"  -->
            <van-image width="170" height="120" :src="`${resourceURL}${item.imageurl}`" fit="cover" />
            <div class="right">

              <div class="name">{{item.product_name}}</div>
              <div class="count">￥{{item.sprice}}</div>

            </div>
          </div>

        </div>
      </div>
    </van-list>
  </div>
</template>
<script>
import { Toast } from "vant";

export default {
  name: '',
  components: {

  },
  mixins: [],
  props: {

  },
  data () {
    return {
      index: 0,
      page: 1,
      list: [],
      loading: false,
      finished: false
    }
  },
  computed: {

  },
  watch: {

  },
  mounted () {

  },
  created () {

    this.getuncommonproduct()
  },
  methods: {
    getList (index) {
      this.finished = false;
      this.index = index
      this.list = []
      switch (this.index) {
        case 0:
          this.getuncommonproduct()
          break;
        case 1:
          this.productlist()
          break;
      }
    },
    onLoad () {
      this.page++
      switch (this.index) {
        case 0:
          this.getuncommonproduct()
          break;
        case 1:
          this.productlist()
          break;
      }
    },
    // 根据获取商品列表
    productlist () {
      this.loading = true
      this.$axios.get(this.$api.productlist, {
        params: {
          nsort: 'desc',
          page: this.page,  //页码
        }
      }).then((res) => {
        if (res.data.code == 1) {
          if (res.data.last_page == res.data.current_page) {
            this.finished = true;
          } else {
            this.finished = false;
          }
          this.page = Number(res.data.data.current_page);
          this.list = this.list.concat(res.data.data.data);

        }
      }).catch(err => {
        Toast.fail(err)
      })
    },
    //获取团餐列表
    getuncommonproduct () {
      this.loading = true
      this.$axios.get(this.$api.getuncommonproduct, {
        params: {
          class_name: "team",
          page: this.page,
          nsort: 'desc'
        }
      }).then((res) => {
        this.loading = false;

        if (res.data.code == 1) {
          if (res.data.last_page == res.data.current_page) {
            this.finished = true;
          } else {
            this.finished = false;
          }
          this.page = Number(res.data.data.current_page);
          this.list = this.list.concat(res.data.data.data);

        }
      })
    }
  }
};
</script>
<style lang='less' scoped>
.TryNewProducts {
  width: 100%;
  background: #11625d;
  min-height: 100vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  .ProductsTitle {
    width: 375px;
    height: 214px;
    overflow: auto;
    background: url(../../assets/img/TryNewProducts/ProductsTitle.png) no-repeat;
    background-size: cover;
    .category {
      margin: 0 auto;
      margin-top: 147px;
      width: 234px;
      height: 38px;
      background: url(../../assets/img/TryNewProducts/category.png) no-repeat;
      background-size: cover;
      box-sizing: border-box;
      padding: 10px 56px;
      padding-right: 40px;
      display: flex;
      justify-content: space-between;
    }
    .group,
    .normal {
      width: 57px;
      height: 100%;
      font-size: 14px;
      font-family: Source Han Sans CN;
      font-weight: 400;

      color: #ffffff;
    }
    .group {
      border-right: 1px solid rgba(255, 255, 255, 0.2);
    }
    .selected {
      font-size: 14px;
      font-family: Source Han Sans CN;
      font-weight: bold;

      color: #f9c254;
      text-shadow: 0px 2px 4px #083e3b;
    }
  }
}
.goodsList {
  width: 331px;
}
.item {
  width: 100%;
  background: url(../../assets/img/my/goodsBox.png) no-repeat;
  background-size: cover;
  height: 128px;
  margin-bottom: 14px;
  padding: 7px;
  box-sizing: border-box;
  .goods {
    box-sizing: border-box;
    border-radius: 23px;
    display: flex;
    justify-content: space-between;
    overflow: hidden;
    border: 1px solid #f9c254;
    color: #f9c254;
    height: 100%;
    .right {
      background: #b60102;
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .name {
        height: 50%;
        margin: 11px;
        margin-bottom: 0;
        font-size: 13px;
        font-family: Microsoft YaHei;
        font-weight: bold;
        margin-top: 13px;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden; //溢出内容隐藏
        text-overflow: ellipsis; //文本溢出部分用省略号表示
        display: -webkit-box; //特别显示模式
        -webkit-line-clamp: 4; //行数
        line-clamp: 4;
        -webkit-box-orient: vertical; //盒子中内容竖直排列
        text-align: left;
      }
      .count {
        height: 50%;
        margin-left: 11px;
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: bold;
      }
    }
  }
}
</style>